home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 1.5)
-
- '''Creation of PYC resources'''
- import os
- import Res
- import __builtin__
- READ = 1
- WRITE = 2
- smAllScripts = -3
-
- def Pstring(str):
- '''Return a pascal-style string from a python-style string'''
- if len(str) > 255:
- raise ValueError, 'String too large'
-
- return chr(len(str)) + str
-
-
- def create(dst, creator = 'Pyth'):
- '''Create output file. Return handle and first id to use.'''
-
- try:
- os.unlink(dst)
- except os.error:
- pass
-
- Res.FSpCreateResFile(dst, creator, 'rsrc', smAllScripts)
- return open(dst)
-
-
- def open(dst):
- output = Res.FSpOpenResFile(dst, WRITE)
- Res.UseResFile(output)
- return output
-
-
- def writemodule(name, id, data, type = 'PYC ', preload = 0, ispackage = 0):
- '''Write pyc code to a PYC resource with given name and id.'''
- if ispackage:
- data = data[:4] + '\xff\x00\x00\x00' + data[8:]
- else:
- data = data[:4] + '\x00\x00\x00\x00' + data[8:]
- res = Res.Resource(data)
- res.AddResource(type, id, name)
- if preload:
- attrs = res.GetResAttrs()
- attrs = attrs | 4
- res.SetResAttrs(attrs)
-
- res.WriteResource()
- res.ReleaseResource()
-
-
- def frompycfile(file, name = None, preload = 0, ispackage = 0):
- '''Copy one pyc file to the open resource file'''
- if name == None:
- (d, name) = os.path.split(file)
- name = name[:-4]
-
- id = findfreeid()
- data = __builtin__.open(file, 'rb').read()
- writemodule(name, id, data, preload = preload, ispackage = ispackage)
- return (id, name)
-
-
- def frompyfile(file, name = None, preload = 0, ispackage = 0):
- '''Compile python source file to pyc file and add to resource file'''
- import py_compile
- py_compile.compile(file)
- file = file + 'c'
- return frompycfile(file, name, preload = preload, ispackage = ispackage)
-
- _firstfreeid = None
-
- def findfreeid(type = 'PYC '):
- '''Find next free id-number for given resource type'''
- global _firstfreeid, _firstfreeid
- id = _firstfreeid
- _firstfreeid = _firstfreeid + 1
- return id
-
-